#ifndef __IOBOT_H
#define __IOBOT_H

#define bot_TOP				0
#define bot_BOTTOM			0
#define bot_LEFT				1
#define bot_RIGHT				1
#define bot_TOP_LEFT			2
#define bot_TOP_RIGHT		3
#define bot_BOTTOM_LEFT		4
#define bot_BOTTOM_RIGHT	5
#define bot_LEADIN			6
#define bot_LEADOUT			7
#define bot_BLANK				8

#define VGA_BLACK				0
#define VGA_BLUE				1
#define VGA_GREEN				2
#define VGA_CYAN				3
#define VGA_RED				4
#define VGA_MAGENTA			5
#define VGA_BROWN				6
#define VGA_GREY_LIGHT		7
#define VGA_GREY_DARK		8
#define VGA_BLUE_LIGHT		9
#define VGA_GREEN_LIGHT		10
#define VGA_CYAN_LIGHT		11
#define VGA_RED_LIGHT		12
#define VGA_MAGENTA_LIGHT	13
#define VGA_BROWN_LIGHT		14
#define VGA_WHITE				15

typedef struct
{
	char *name;
	int focused;

	unsigned int x;
	unsigned int y;
	unsigned int width;
	unsigned int height;

	unsigned int textwidth;
	unsigned int textheight;
	unsigned int csr_x;
	unsigned int csr_y;
	unsigned int scroll;

	unsigned char dirty;
	unsigned int dirty_x;
	unsigned int dirty_y;
	unsigned int dirty_width;
	unsigned int dirty_height;

	unsigned char botout[12288];//just over 3 pages worth of 80x50 text, 12 kilobytes
	unsigned int botin_write_pos;
	unsigned int botin_read_pos;
	unsigned char botin[1024];//a 1 kilobyte input buffer

	unsigned int scrl;
	unsigned int num;
	unsigned int caps;
	unsigned int capslock;
	unsigned int ctrl;
	unsigned int alt;
	
}iobot_t;

iobot_t* iobot_create(char* name, unsigned int x, unsigned int y, unsigned int w, unsigned int h);
void iobot_destroy(iobot_t* bot);

//reads all input from the keyboard, interprets the scan codes (letters, escape sequences etc.),
//and writes the results to stdin.
void iobot_update_input(iobot_t *bot);
void iobot_process_scancode(iobot_t *bot, unsigned char scncode);
void iobot_clear_input(iobot_t *bot);
void iobot_put_input_string(iobot_t *bot, char* string);

//writes the contents of stdout to the screen, interpreting color escape sequences etc.
void iobot_update_output(iobot_t *bot);
void iobot_clear_output(iobot_t *bot);

//returns and flushes the next character from stdin. Returns zero when there are no more characters.
unsigned char iobot_get_char(iobot_t *bot);

//writes to stdout in various formats
void iobot_put_char(iobot_t *bot, unsigned char c);
void iobot_put_string(iobot_t *bot, char *str);
void iobot_put_number(iobot_t *bot, unsigned int num);
void iobot_put_hex(iobot_t *bot, unsigned int num);

void iobot_backspace(iobot_t *bot);
void iobot_delete(iobot_t* bot);
void iobot_scroll(iobot_t* bot, int num_lines);

void draw_iobots();
void dirty_all_iobots();
void add_iobot(iobot_t *bot);
void remove_iobot(iobot_t *bot);
//void cycle_iobots(iobot_t *currentbot);

#endif
